﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE80;
using TSVNAddin.VS;

namespace TSVNAddinUtils
{
	public class RemoveBarCommand : IUtilsCommand
	{
		private readonly DTEInstanceCreator _DTEInstanceCreator;
		private readonly GenericFactory _GenericFactory;

		public RemoveBarCommand(DTEInstanceCreator dteInstanceCreator, GenericFactory genericFactory)
		{
			_DTEInstanceCreator = dteInstanceCreator;
			_GenericFactory = genericFactory;
		}

		public virtual void Exec(string[] args)
		{
			DTE2 dte = null;
			try
			{
				dte = _DTEInstanceCreator.CreateInstance();

				MenuBarAdapter menuBar = _GenericFactory.Createinstace<MenuBarAdapter>(dte);
				menuBar.RemoveTortoiseCommandBar();

				Console.WriteLine("TortoiseCommandBar removed...");
			}
			catch (Exception ex)
			{
				Console.WriteLine("Exception: " + ex.Message);
			}
			finally
			{
				if (dte != null)
					dte.Quit();

				System.Threading.Thread.Sleep(1000);
			}
		}
	}
}
